﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports GenDotNet.Task.Common

Public Class VariableInfo
   Inherits BaseInfo

   Private mInfer As Boolean
   Private mNetType As NetTypeInfo
   Private mDefaultValue As String
   Private mSetNew As Boolean
   Private mIsLocal As Boolean

   Public Sub New( _
            ByVal name As String, _
            ByVal isLocal As Boolean, _
            ByVal netType As NetTypeInfo)
      MyBase.New(name, Scope.Unknown)
      Me.mIsLocal = isLocal
      Me.mNetType = netType
      Me.mSetNew = SetNew
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal scope As Scope, _
            ByVal netType As NetTypeInfo)
      MyBase.New(name, scope)
      Me.mNetType = netType
      Me.mSetNew = SetNew
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal scope As Scope, _
            ByVal netType As NetTypeInfo, _
            ByVal defaultValue As String)
      MyBase.New(name, scope)
      Me.mNetType = netType
      Me.mDefaultValue = defaultValue
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal scope As Scope, _
            ByVal netType As NetTypeInfo, _
            ByVal setNew As Boolean)
      MyBase.New(name, scope)
      Me.mNetType = netType
      Me.mSetNew = setNew
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal isLocal As Boolean, _
            ByVal netType As NetTypeInfo, _
            ByVal defaultValue As String, _
            ByVal infer As Boolean)
      MyBase.New(name, Scope.Unknown)
      Me.mIsLocal = isLocal
      Me.mNetType = netType
      Me.mDefaultValue = defaultValue
      Me.mInfer = Infer
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal isLocal As Boolean, _
            ByVal netType As NetTypeInfo, _
            ByVal setNew As Boolean, _
            ByVal infer As Boolean)
      MyBase.New(name, Scope.Private)
      Me.mIsLocal = isLocal
      Me.mNetType = netType
      Me.mSetNew = setNew
      Me.mInfer = Infer
   End Sub

   Public Property NetType() As NetTypeInfo
      Get
         Return mNetType
      End Get
      Set(ByVal value As NetTypeInfo)
         mNetType = value
      End Set
   End Property

   Public Property DefaultValue() As String
      Get
         Return mDefaultValue
      End Get
      Set(ByVal value As String)
         mDefaultValue = value
      End Set
   End Property

   Public Property SetNew() As Boolean
      Get
         Return mSetNew
      End Get
      Set(ByVal value As Boolean)
         mSetNew = value
      End Set
   End Property

   Public Property IsLocal() As Boolean
      Get
         Return mIsLocal
      End Get
      Set(ByVal value As Boolean)
         mIsLocal = value
      End Set
   End Property

   Public Property Infer() As Boolean
      Get
         Return mInfer
      End Get
      Set(ByVal value As Boolean)
         mInfer = value
      End Set
   End Property


End Class

Namespace VB
   Public Module VariableInfoExtensions
      <Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As VariableInfo) As String
         Return _
   <code>
      <%= If(info.IsLocal, "Dim", info.Scope.Output).WithSpace %><%= info.Name %>
      <%= If(info.SetNew Or (info.Infer And Not String.IsNullOrEmpty(info.DefaultValue)), String.Empty, " As " & info.NetType.Output) %>
      <%= If(Not String.IsNullOrEmpty(info.DefaultValue), " = " & info.DefaultValue, _
         If(Not info.SetNew, String.Empty, " = New " & info.NetType.Output & "()")) %>
      <%= Strings.nl %>
   </code>.Value
      End Function
   End Module
End Namespace

Namespace CSharp
   Public Module VariableInfoExtensions
      <Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As VariableInfo) As String
         Return _
   <code>
      <%= If(info.IsLocal, String.Empty, info.Scope.Output).WithSpace %><%= info.NetType.Output.WithSpace %><%= info.Name %>
      <%= If(String.IsNullOrEmpty(info.DefaultValue), String.Empty, " = " & info.DefaultValue) %>;
   </code>.Value
      End Function
   End Module
End Namespace